
#include <iostream>
#include <talos/IOPort.hpp>
#include <pthread.h>

class MyInt
{
	public:
		MyInt() : m_test( -5 )
		{
			NotifyChange( MyInt, onNewInt, m_int);
			m_int << -1;
		}

		talos::IOPort< int > m_int;
		int m_test;

		DeclareNotifier( MyInt, onNewInt, int );

		void onNewInt( int inputPort )
		{
			std::cout << "My Int is : " << inputPort << std::endl;
			m_test = inputPort;
		}
};

class YourInt
{
	public:
		YourInt() : m_test( -13 )
		{
			NotifyChange( YourInt, onNewInt, m_int );
			m_int << 0;
		}

		talos::IOPort< int > m_int;
		int m_test;

		DeclareNotifier( YourInt, onNewInt, int );
		void onNewInt( int inputPort )
		{
			std::cout << "Your Int is : " << inputPort << std::endl;
			m_test = inputPort;
		}
};

int main()
{
	std::cout << "BEGIN HERE" << std::endl;

	MyInt toto;
	YourInt tata;

	if ( toto.m_test == -1 && tata.m_test == 0 )
	{
		std::cout << "TEST 1 : OK" << std::endl;
	}
	else
	{
		std::cout << "TEST 1 : BROKEN" << std::endl;
		std::cout << toto.m_test << "  " << tata.m_test << std::endl;
	}

	tata.m_int = toto.m_int;  // synchronize
	toto.m_int << 43;         // assign

	if ( toto.m_test == 43 && tata.m_test == 43 )
	{
		std::cout << "TEST 2 : OK" << std::endl;
	}
	else
	{
		std::cout << "TEST 2 : BROKEN" << std::endl;
		std::cout << toto.m_test << "  " << tata.m_test << std::endl;
	}

	tata.m_int << 72;         // assign

	if ( toto.m_test == 72 && tata.m_test == 72 )
	{
		std::cout << "TEST 3 : OK" << std::endl;
	}
	else
	{
		std::cout << "TEST 3 : BROKEN" << std::endl;
		std::cout << toto.m_test << "  " << tata.m_test << std::endl;
	}

	std::cout << "END HERE" << std::endl;
}

